//
//  ChangeViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/28.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class ChangeViewController: KMViewController {

    fileprivate let changeView = ChangeView()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = changePassword
//        self.navigationController?.navigationBar.isTranslucent = false
        addSubView()
    }
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
        changeView.changeBtn.addTarget(self, action: #selector(changeAction), for: .touchUpInside)
        self.view.addSubview(changeView)
        
        changeView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
    }
    
    //MARK: 修改密码
    @objc fileprivate func changeAction() {
        
        KMTool.waiting()
        KMTool.requestMethod(.post, URLString: url_changePassword, parameters: ["user_name":KMTool.stringForEnumKey(.phone) ?? "","oldpassword":changeView.oldPWView.textView.text!,"password":changeView.newPWView.textView.text!,"repassword":changeView.confirmPWView.textView.text!], success: { (value, json) in
            
            KMTool.stop()
            if json["status"].stringValue == "0" {
                KMTool.showText(_text: changeSuccess)
                self.navigationController?.popViewController(animated: true)
            }else{
                KMTool.showText(_text: json["msg"].stringValue)
            }
        }) {
            
            KMTool.stop()
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
